package com.gxgeek.javabasic.collection.map;

import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

/**
 * Created by GX on 2017/8/24.
 */
@Slf4j
public class AnalyzelHashMap {


    public static void main(String[] args) {
        addAllMap();

//        addmap();
//        dosomething();
    }

    private static void addAllMap() {
        HashMap map = new HashMap((int) (24 *0.75+1));
        for (int i = 0 ;i<24;i++){
            map.put(i,i);
        }
        System.out.println();
    }

    private static void addmap() {
        HashMap<String,String> map = new HashMap<>();
        Map<String,String> treeMap = new TreeMap<>();
        map.put("1","赵一");
        map.put("2","王二");
        map.put("3","张三");
        map.put("6","孙七");
        map.put("5","李四");
        map.put("19","Gxgeek");
        Iterator iterator = map.entrySet().iterator();
        while (iterator.hasNext()){
            log.info(iterator.next().toString());
        }
//        map.keySet().iterator();
//        map.get("");
////        map.get();
//        int [] ints = new int[16];
//        log.info(String.valueOf(ints.length));
//        dosomething();
//        map.get();
        int [] ints = new int[16];
        log.info(String.valueOf(ints.length));
    }

    public static void dosomething(){
         int MAX = 32;
         int index = 31;

        index = 31;
        index = (index + 1) % MAX;  // 这个容易理解
        log.info("index = %d\n{}",index);
        index = 31;
        index = (index + 1) & (MAX - 1);  // 这个运算效率高
        log.info("index = %d\n {}", index);

    }
    static final int hash(Object key) {
        if(key == null)
            return 0;
        int h = key.hashCode();
        int temp = h >>> 16;
        int newHash = h ^ temp;
        return newHash;
    }


}
